package cn.wolfcode.car.business.web.controller.system;


import cn.wolfcode.car.business.domain.Statement;
import cn.wolfcode.car.business.domain.StatementItem;
import cn.wolfcode.car.business.query.StatementItemQuery;
import cn.wolfcode.car.business.service.IStatementItemService;
import cn.wolfcode.car.business.service.IStatementService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 客户控制器
 */
@Controller
@RequestMapping("/business/statementItem")
public class StatementItemController {
    //模板前缀
    private static final String prefix = "business/statementItem/";

    @Autowired
    private IStatementItemService statementItemService;
    @Autowired
    private IStatementService statementService;



    //数据-----------------------------------------------------------
    //列表
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<StatementItem> query(Model model, StatementItemQuery qo){
        System.out.println("=============================================");
        System.out.println(statementItemService.query(qo));

        return statementItemService.query(qo);
    }
@RequestMapping("/itemDetail")
    public String itemDetail(Model model,StatementItemQuery qo){
        Statement statement = statementService.get(qo.getStatementId());
        model.addAttribute("statement",statement);
        if (Statement.STATUS_CONSUME.equals(statement.getStatus())){
            return "business/statementItem/editDetail";
        }else {
            return "business/statementItem/billDetail";
        }
    }

    @RequestMapping("/saveItems")
    @ResponseBody
    public AjaxResult saveItems(@RequestBody List<StatementItem> list){
        statementItemService.saveItem(list);
        return AjaxResult.success();
    }

    @RequestMapping("/pay")
    @ResponseBody
    public AjaxResult pay(Long statementId){
        statementService.pay(statementId);
        return AjaxResult.success();
    }
}
